package com.cy.pj.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.sys.dao.SysOrderDao;
import com.cy.pj.sys.entity.SysOrder;
import com.cy.pj.sys.entity.SysUser;
import com.cy.pj.sys.service.SysOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @description 订单操作Service层实现类
 * @author dxy 2216874549@qq.com
 * @date 2019/12/8 23:34
 * @version 1.0
 * @since 1.8
 */
@Slf4j
@Service
public class SysOrderServiceImpl extends ServiceImpl<SysOrderDao, SysOrder> implements SysOrderService {

    /**
     * @description 保存订单
     * @author dxy 2216874549@qq.com
     * @date 2019/12/8 23:39
     * @param [sysOrder] 订单
     * @return boolean
     * @version 1.0
     * @since 1.8
     */
    @Override
    @Transactional
    @RequiresPermissions("sys:order:add")
    @RequiredLog("添加订单")
    public boolean save(SysOrder sysOrder) {
        SysUser user = (SysUser)SecurityUtils.getSubject().getPrincipal();//获取当前登录的用户信息
        sysOrder.setId(getOrderId());
        sysOrder.setUserId(user.getId());
        sysOrder.setCreatedTime(new Date());
        sysOrder.setCreatedUser(user.getUsername());
        return super.save(sysOrder);
    }

    /**
     * @description 生成订单编号
     * @author dxy 2216874549@qq.com
     * @date 2019/12/8 23:41
     * @param []
     * @return java.lang.String
     * @version 1.0
     * @since 1.8
     */
    private String getOrderId() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String str1 = sdf.format(new Date());
        String str2 = UUID.randomUUID().toString().replace("-","");
        return str1+str2;
    }

    /**
     * @description 订单列表分页查询
     * @author dxy 2216874549@qq.com
     * @date 2019/12/11 21:48
     * @param [pageCurrent, pageSize, orderName]
     * @return java.util.List<java.lang.Object>
     * @version 1.0
     * @since 1.8
     */
    @Override
    public List<Object> findByPage(Integer pageCurrent, Integer pageSize, String orderName) {
        SysUser user = (SysUser)SecurityUtils.getSubject().getPrincipal();//获取当前登录的用户
        return null;
    }
}
